﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class PrintDelivery : AdminPage
    {
        BLL.CNVP_Order bll = new BLL.CNVP_Order();
        Model.CNVP_Order model = new Model.CNVP_Order();
        public int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 94)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]) && Public.IsNumber(Request.QueryString["ID"].ToString()))
            {
                id = Convert.ToInt32(Request.QueryString["ID"]);
            }
            if (!IsPostBack)
            {
                PrintDeliveryInfo();
            }
        }
        private void PrintDeliveryInfo()
        {
            model = bll.GetSingle_CNVP_OrderById(id);
            if (model != null)
            {
                string html = "";
                html += "           <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table_frame\" width=\"100%\">";
                html += "            <tr>";
                html += "                <td>";
                //Begin 头部
                html += "    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
                html += "        <tr>";
                html += "            <td width=\"40%\">";
                html += "";
                html += "            </td>";
                html += "            <td style=\"FONT-SIZE: 16pt\">";
                html += "                <strong>" + model.OrderNum + "</strong></td>";
                html += "            <td>";
                html += "                 <div class=\"noprint\">";
                html += "                   <input id=\"chk_pic_print\" name=\"chk_pic_print\" type=\"checkbox\" checked=\"checked\" onclick=\"DeliveryIsPrintPic();\" />打印图片";
                html += "                   <input id=\"chk_address_print\" name=\"chk_address_print\" type=\"checkbox\" checked=\"checked\" onclick=\"IsPrintAddress();\" />打印配送地址";
                html += "                 </div>";
                html += "            </td>";
                html += "        </tr>";
                html += "        <tr>";
                html += "            <td colspan=\"2\" width=\"70%\">";
                html += "                <p>";
                html += "                    订单号<strong>：" + model.OrderNum + "</strong>";
                html += "                </p>";
                html += "                <p>";
                html += "                    日期：" + model.PostTime + "</p>";
                html += "            </td>";
                html += "            <td width=\"30%\">";
                html += "                <p>";
                html += "                    客户：" + model.GetTrueName + "</p>";
                html += "                <p>";
                html += "                    手机：" + model.MobilePhone + "</p>";
                html += "                <p>";
                html += "                    电话：" + model.Phone + "</p>";
                html += "            </td>";
                html += "        </tr>";
                html += "    </table>";
                //End 头部
                html += "                </td>";
                html += "            </tr>";
                html += "            <tr>";
                html += "                <td class=\"td_frame\">";
                html += "                    <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\">";
                html += "                        <tr class=\"table_data_title\">";
                html += "                            <td width=\"40\">";
                html += "                                序号</td>";
                html += "                            <td>";
                html += "                                货号</td>";
                html += "                            <td>";
                html += "                                货位</td>";
                html += "                            <td>";
                html += "                                商品名称</td>";
                html += "                            <td align=\"middle\">";
                html += "                                单价</td>";
                html += "                            <td align=\"middle\" width=\"50\">";
                html += "                                数量</td>";
                html += "                            <td align=\"middle\">";
                html += "                                小计</td>";
                html += "                        </tr>";
                string Addtr = "";
                var OrderProducts_List = new BLL.CNVP_OrderProducts().GetAll_CNVP_OrderProducts(id);
                for (int i = 0; i < OrderProducts_List.Count; i++)
                {

                    Addtr += "                        <tr>";
                    Addtr += "                            <td>";
                    Addtr += "                                " + (i + 1) + "</td>";
                    Addtr += "                            <td>";
                    Addtr += "                                " + OrderProducts_List[i].ProductNo + "";
                    Addtr += "                             </td>";
                    Addtr += "                            <td>";
                    var listProduct = new BLL.CNVP_Products().GetSingle_CNVP_ProductsById(OrderProducts_List[i].ProductID);
                    var model_ProductsDetail = new BLL.CNVP_ProductsDetail().GetSingle_CNVP_ProductsDetailById(OrderProducts_List[i].ProductsDetailID);
                    string _Allocation = string.Empty;
                    if (OrderProducts_List[i].ProductsDetailID != 0)
                    {
                        if (model_ProductsDetail != null)
                        {
                            _Allocation = model_ProductsDetail.Allocation;
                        }
                    }
                    else
                    {
                        if (listProduct != null)
                        {
                            _Allocation = listProduct.Allocation;
                        }
                    }
                    Addtr += "                                " + _Allocation + "";
                    Addtr += "                            </td>";
                    Addtr += "                            <td>";
                    Addtr += "                      <a href=\"/ProductDetail_" + OrderProducts_List[i].ProductClassID + "_" + OrderProducts_List[i].ProductID + ".aspx\" target=\"_blank\" title=\"" + OrderProducts_List[i].ProductName + "\">";
                    Addtr += "                                  <img align=\"absMiddle\" class=\"DeliveryIsPrintPic\" src=\"../UploadFile/Product/" + OrderProducts_List[i].ImgProLoad + "\" width=\"45\" />";
                    Addtr += "                       </a>";
                    Addtr += "                      <a href=\"/ProductDetail_" + OrderProducts_List[i].ProductClassID + "_" + OrderProducts_List[i].ProductID + ".aspx\" target=\"_blank\" title=\"" + OrderProducts_List[i].ProductName + "\">";
                    Addtr += "                                " + OrderProducts_List[i].ProductName + "";
                    Addtr += "                       </a>";
                    Addtr += "                                </td>";
                    Addtr += "                            <td>";
                    Addtr += "                                ￥" + OrderProducts_List[i].Price + "元</td>";
                    Addtr += "                            <td>";
                    Addtr += "                                " + OrderProducts_List[i].Num + "</td>";
                    Addtr += "                            <td>";
                    Addtr += "                                ￥" + OrderProducts_List[i].TotalPrice + "元</td>";
                    Addtr += "                        </tr>";
                }
                html += Addtr;
                html += "                    </table>";
                html += "                </td>";
                html += "            </tr>";
                html += "            <tr>";
                html += "                <td>";
                html += "                    <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
                html += "                        <tr>";
                html += "                            <td style=\"HEIGHT: 150px\" valign=\"top\" width=\"50%\">";
                html += "                                <p>";
                html += "                                    备注：" + model.Text + "</p>";
                html += "                            </td>";
                html += "                            <td valign=\"top\" width=\"50%\">";
                html += "                                <div id=\"print_address\">";
                html += "                                    <p>";
                html += "                                        配　送：" + model.DeliveryWay + "</p>";
                html += "                                    <p>";
                html += "                                        收货人：" + model.GetTrueName + "</p>";
                html += "                                    <p>";
                html += "                                        电　话：" + model.Phone + "</p>";
                html += "                                    <p>";
                html += "                                        手　机：" + model.MobilePhone + "</p>";
                string Address_Str = new BLL.CNVP_Province().GetSingle_CNVP_ProvinceByCode(model.Province).Name + "" + new BLL.CNVP_City().GetSingle_CNVP_CityByCode(model.City).Name;
                Address_Str += new BLL.CNVP_Area().GetSingle_CNVP_AreaByCode(model.Area).Name + model.GetAddress;
                html += "                                    <p>";
                html += "                                        地　址：" + Address_Str + "</p>";
                html += "                                    <p>";
                html += "                                        邮　编：" + model.ZipCode + "</p>";
                html += "                                </div>";
                html += "                            </td>";
                html += "                        </tr>";
                html += "                    </table>";
                html += "                </td>";
                html += "            </tr>";
                html += "            <tr>";
                html += "                <td style=\"HEIGHT: 100px\">";
                html += "                    <h1>";
                html += "                        签字：</h1>";
                html += "                </td>";
                html += "            </tr>";
                html += "            <tr>";
                html += "                <td align=\"right\" style=\"PADDING-BOTTOM: 50px; HEIGHT: 30px\">";
                html += "                    <strong>" + Config.UIConfig.Powered + "</strong></td>";
                html += "            </tr>";
                html += "        </table>";
                lbPrintDelivery.Text = html;
            }
        }
    }
}
